Skip to content

Use a simpler :prefix-name: syntax for icon fonts#680

Merged
yamgent merged 3 commits into
MarkBind:masterfrom
Xenonym:colon-iconfont-syntax
Feb 18, 2019
Merged

Use a simpler :prefix-name: syntax for icon fonts#680
yamgent merged 3 commits into
MarkBind:masterfrom
Xenonym:colon-iconfont-syntax

Conversation

@Xenonym

@Xenonym Xenonym commented Feb 8, 2019

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [X] Enhancement to an existing feature

Resolves #612.

What is the rationale for this request?
Currently, we use the {{ prefix_name }} syntax for inserting icon fonts from Font Awesome and Glyphicons. It would be ideal to support a simpler :prefix-name: syntax, similar to how we support :emoji:.

What changes did you make? (Give an overview)

Provide some example code that this change will affect:

- FA university icon: :fas-university:
- Glyphicon icon: :glyphicon-home:

Testing instructions:

  1. Add the above sample code to a MarkBind page and markbind serve. The icons should render:

Example render of :prefix-name: icon fonts

Comment thread docs/index.md Outdated
@Chng-Zhi-Xuan Chng-Zhi-Xuan self-requested a review February 8, 2019 06:04

@acjh acjh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's officially deprecate the variables syntax for icons.

Comment thread src/lib/markbind/src/lib/markdown-it/index.js Outdated

@yamgent yamgent left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A search for {{glyphicon still returns files that are using the old syntax.

Comment thread src/lib/markbind/src/lib/markdown-it/markdown-it-icons.js Outdated
@Chng-Zhi-Xuan

Copy link
Copy Markdown
Contributor

Seems like there are some icons that are not rendered.

In reusingcontents.md
unrendered-icons

@Xenonym

Xenonym commented Feb 11, 2019

Copy link
Copy Markdown
Contributor Author

Seems like there are some icons that are not rendered.

@Chng-Zhi-Xuan good catch! Turns out a preceding line break from the last <div> tag is needed, since we need to interpret the text as Markdown for markdown-it to parse the icon fonts.

@Xenonym

Xenonym commented Feb 11, 2019

Copy link
Copy Markdown
Contributor Author

A search for {{glyphicon still returns files that are using the old syntax.

@yamgent Yes, since these are still used to test variables. Since we are only deprecating the syntax for the next release, I think we still have to keep them to ensure that existing uses don't break until when we remove the syntax altogether. Also, there are some issues related to testing since we will not have static built-in variables after we remove the {{ prefix_name }} syntax. From the PR:

Some {{ prefix_name }} usages that were not changed because they are implicitly used to test variables:

  • In Site.js#FOOTER_DEFAULT:
    'This is a dynamic height footer that supports variables {{glyphicon_tags}}'
  • In Site.test.js#test('Site resolves variables referencing other variables'):
    '<span id="level3">{{glyphicon_plus}}</span>'

When we remove icon font variables, the only remaining built-in variable with HTML will be {{ MarkBind }}. Since {{ MarkBind }} changes with every new version, I am unsure if it is a good candidate for automated testing.

Comment thread docs/index.md
@Chng-Zhi-Xuan

Copy link
Copy Markdown
Contributor

When we remove icon font variables, the only remaining built-in variable with HTML will be {{ MarkBind }}. Since {{ MarkBind }} changes with every new version, I am unsure if it is a good candidate for automated testing.

I think it is fine to swap over to the new syntax completely, We can just add unit tests in test_site to test any old syntax required.

@acjh

acjh commented Feb 13, 2019

Copy link
Copy Markdown
Contributor

@Chng-Zhi-Xuan By completely, do you mean including {{ MarkBind }}?

Note that this PR does not (should not) introduce a new syntax for variables, just "constant" icons.

@Chng-Zhi-Xuan

Copy link
Copy Markdown
Contributor

@acjh I am referring to the Glyphicons using the old syntax. Since this PR is meant to improve icon syntax only.

@Chng-Zhi-Xuan

Copy link
Copy Markdown
Contributor

@Xenonym, I looked through again and seems ok.

However, we should change our documentation and tests to follow the new icon syntax in this PR. "Implicit testing" of old syntax by intentionally leaving some icons with old syntax in templates or tests is not clean.

Please do change the FOOTER_DEFAULT template in Site.js which uses icons, to the new syntax. I found other instances in Site.test.js and test_site using the old icon syntax as well.

Once you're done, I can give the green light 👍

- convert uses of {{ prefix_name }} to :prefix-name:
- modify tests that rely on {{ prefix_name }} to use other variables
- new example for variables that contain HTML tags to replace the old one which uses {{ prefix_name }}
@Xenonym

Xenonym commented Feb 15, 2019

Copy link
Copy Markdown
Contributor Author

Please do change the FOOTER_DEFAULT template in Site.js which uses icons, to the new syntax. I found other instances in Site.test.js and test_site using the old icon syntax as well.

@Chng-Zhi-Xuan made the necessary changes! Here's a summary:

  • Removed {{glyphicons_tag}} from FOOTER_DEFAULT. The use of {{MarkBind}} and {{timestamp}} already serve as a means to demonstrate variables.
  • Removed {{education_icon}} from test_site.
  • Modified test('Site resolves variables referencing other variables') to use a custom variable instead.
  • Used a <span> instead of <font> tag for the code example in reusingContents.md since the <font> tag is deprecated.

@Chng-Zhi-Xuan Chng-Zhi-Xuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, looks good 👍

Good point on the <font> element being obsolete. Although I still find numerous instances of using it within our documentation / code base.

@Xenonym Do open up an issue to refactor <font> elements in a separate PR.

@yamgent yamgent added this to the v1.18.1 milestone Feb 17, 2019
@yamgent yamgent merged commit dc53e76 into MarkBind:master Feb 18, 2019
@Xenonym Xenonym deleted the colon-iconfont-syntax branch February 18, 2019 02:35
@damithc

damithc commented Feb 18, 2019

Copy link
Copy Markdown
Contributor

Gave it a try. Works as intended. Nice work @Xenonym and reviewers.

One small nit. This extra space can be misleading (not sure if it was introduced in this PR or not).

image

@Chng-Zhi-Xuan

Copy link
Copy Markdown
Contributor

That extra space was already present before the icon syntax change PR. The blank space is caused by the <code> tag having padding on the left and right side. There are 2 inline code blocks (fab- and file-code etc) so the result looks like an additional space in-between.

Snippet from icons.mbdf

   * _Solid_ (prefix: `fas-`) e.g., :fas-file-code: (actual name `file-code`, MarkBind name **`fas-`**`file-code`)
   * _Regular_ (prefix: `far-`) e.g., :fas-file-code: (actual name `file-code`, MarkBind name **`far-`**`file-code`)
   * _Brands_ (prefix: `fab-`): e.g., :fab-github-alt: (actual name `github-alt`, MarkBind name **`fab-`**`github-alt`)

@damithc

damithc commented Feb 18, 2019

Copy link
Copy Markdown
Contributor

That extra space was already present before the icon syntax change PR. The blank space is caused by the <code> tag having padding on the left and right side. There are 2 inline code blocks (fab- and file-code etc) so the result looks like an additional space in-between.

I guess it is a legacy problem. It's better to fix it though. We can sacrifice the bolding. On a related note, I hope we can add a proper way to highlight/bold parts of code some day.

Chng-Zhi-Xuan added a commit to Chng-Zhi-Xuan/markbind that referenced this pull request May 21, 2019
The files were used as a template to build the iconsMap
for using variable syntax to insert icons.

Since MarkBind#680, we have shifted to another syntax for inserting
icons. We made the decision to depreciate the old
variable syntax. Thus it renders the current icon .csv files
as obsolete.

Let's remove these files as well when depreciating the
variable syntax for icons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use a simpler syntax for glyphicons/fontawesome

5 participants